package com.its.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.its.model.User;
import com.its.service.UserService;
import com.its.util.JSONDataResult;
import com.its.util.JSONResult;

@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	UserService userService;
	
	@RequestMapping(value = "login" ,method = RequestMethod.GET)
	public String getLogin() {
		return "user/login";
	}
	
	@ResponseBody
	@RequestMapping(value = "login" ,method = RequestMethod.POST)
	public JSONResult login(String userName,String password) {
		int code = 400;
		String message = null;

		User user = userService.login(userName, password);
		if(user != null) {
			code = 200;
			message = "登陆成功";
		}else {
			code = 404;
			message = "用户名或密码错误";
		}
		return new JSONResult(code, message);
		
	}
	
}
